"use client";

import { useFormState, useFormStatus } from "react-dom";
import { addUser } from "./dashboard-actions";

function SubmitButton() {
  const { pending } = useFormStatus();

  return (
    <button type="submit" aria-disabled={pending}>
      Add
    </button>
  );
}
export default function UserForm() {
  const [state, formAction] = useFormState(addUser, {
    name: "hello",
    age: 0,
    error: "",
  });
  return (
    <form className="flex flex-col" action={formAction}>
      <label htmlFor="name">Name</label> <input name="name"></input>
      <label htmlFor="name">age</label> <input name="age"></input>
      <button type="submit">Submit</button>
    </form>
  );
}
